package com.jar.exercise.网络编程.BIO和NIO和AIO;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * BIO（Blocking-IO）
 * 同步阻塞的
 */

class Server {
	private static final byte[] B = new byte[1024];

	public static void main(String[] args) throws IOException {

		ServerSocket serverSocket = new ServerSocket(12000);
		System.out.println("服务器等待连接。。。。");
		Socket accept = serverSocket.accept();
		String ip = accept.getInetAddress().getHostAddress();
		System.out.println("服务器收到来自：" + ip + "的连接....");
		while (true) {
			InputStream input = accept.getInputStream();
			System.out.println("服务等待接收内容");
			int read = input.read(B);
			System.out.println("服务器收到内容：" + new String(B, 0, read));
		}

	}
}

class Client {
	public static void main(String[] args) throws IOException {
		Socket socket = new Socket("127.0.0.1", 12000);
		while (true) {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			PrintWriter pw = new PrintWriter(socket.getOutputStream(), true);
			String line = br.readLine();
			pw.println(line);
		}
	}
}
